from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAdminUser
from django.contrib.auth.models import Permission,ContentType,Group
from users.models import User
from meiduo_admin.serializers.permissions import PermissionSerializer, ContenttypeSerializer, GroupSerializer
from meiduo_admin.utils import PageNum


class PermissionView(ModelViewSet):
    permission_classes = [IsAdminUser]
    queryset = Permission.objects.all()
    serializer_class = PermissionSerializer
    pagination_class = PageNum

    def content_type(self,request):
        data = ContentType.objects.all()
        ser = ContenttypeSerializer(instance=data,many=True)

        return Response(ser.data)


class GroupView(ModelViewSet):
    permission_classes = [IsAdminUser]
    queryset = Group.objects.all()
    serializer_class = GroupSerializer
    pagination_class = PageNum

    def simple(self,request):
        data = Permission.objects.all()
        ser = PermissionSerializer(data,many=True)
        return Response(ser.data)

